home *** CD-ROM | disk | FTP | other *** search
/ Software USA: Back to School / Software USA: Back to School.iso / pc / children / decoder / run / decoder.exe / decoder.dxr / script_1_main engine.ls < prev    next >
Encoding:
Text File  |  1996-11-19  |  9.4 KB  |  294 lines

  1. global gValidKeyList, gUpperCaseTable
  2.  
  3. on startMovie
  4.   installMenu("menu")
  5.   set the visible of sprite 8 to 0
  6.   set gValidKeyList to ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "?", "!", ",", ".", "-", "$", " ", "@", TAB]
  7.   set gUpperCaseTable to ["!": 33, "$": 36, ",": 44, "-": 45, ".": 46, "0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "?": 63, "a": 65, "b": 66, "c": 67, "d": 68, "e": 69, "f": 70, "g": 71, "h": 72, "i": 73, "j": 74, "k": 75, "l": 76, "m": 77, "n": 78, "o": 79, "p": 80, "q": 81, "r": 82, "s": 83, "t": 84, "u": 85, "v": 86, "w": 87, "x": 88, "y": 89, "z": 90, "@": 64]
  8. end
  9.  
  10. on encode
  11.   if field "encode:name" = EMPTY then
  12.     alert("Please enter your name!")
  13.     exit
  14.   end if
  15.   if field "To be Encoded" = EMPTY then
  16.     alert("There is no message to encode!")
  17.     exit
  18.   end if
  19.   set temp to EMPTY
  20.   set nameField to convertToUpperCase(the text of field "encode:name")
  21.   repeat with y = 1 to the number of chars in nameField
  22.     set holder to charToNum(char y of nameField) + 5
  23.     set holder to numToChar(holder)
  24.     put holder after temp
  25.   end repeat
  26.   put "!" after temp
  27.   set messageField to convertToUpperCase(the text of field "To be Encoded")
  28.   repeat with x = 1 to the number of chars in messageField
  29.     set holder to charToNum(char x of messageField) + 5
  30.     set holder to numToChar(holder)
  31.     put holder after temp
  32.   end repeat
  33.   doSomeFancyStuff()
  34.   put temp into field "encode:result"
  35. end
  36.  
  37. on decode
  38.   set the editable of member "To be Decoded" to 0
  39.   puppetTransition(3)
  40.   updateStage()
  41.   if field "To be Decoded" = EMPTY then
  42.     alert("Please enter the message you want to encode!")
  43.     puppetTransition(3)
  44.     set the editable of member "To be Decoded" to 1
  45.     abort()
  46.   end if
  47.   if the number of chars in field "To be Decoded" > 100 then
  48.     alert("The message is not properly formated:" & RETURN & "Message too long!")
  49.     puppetTransition(3)
  50.     set the editable of member "To be Decoded" to 1
  51.     abort()
  52.   end if
  53.   checkForValidFormate()
  54.   set temp to EMPTY
  55.   repeat with x = 1 to the number of chars in field "To be Decoded"
  56.     set holder to charToNum(char x of field "To be Decoded") - 5
  57.     if holder = 28 then
  58.       set nameOfSender to temp
  59.       set temp to EMPTY
  60.       next repeat
  61.     end if
  62.     set holder to numToChar(holder)
  63.     put holder after temp
  64.   end repeat
  65.   set deCodeResult to temp
  66.   set nameOfSender to checkBadWord(nameOfSender)
  67.   set deCodeResult to checkBadWord(deCodeResult)
  68.   displayResult(nameOfSender, deCodeResult)
  69. end
  70.  
  71. on checkBadWord theString
  72.   repeat with i = 1 to the number of words in theString
  73.     repeat with j = 1 to the number of words in field "bad words"
  74.       if word i of theString = word j of field "bad words" then
  75.         repeat with k = 1 to the number of chars in word i of theString
  76.           put "?" into char k of word i of theString
  77.         end repeat
  78.         next repeat
  79.       end if
  80.       next repeat
  81.     end repeat
  82.   end repeat
  83.   return theString
  84. end
  85.  
  86. on checkForValidFormate
  87.   if field "To be Decoded" contains "!" then
  88.     set the itemDelimiter to "!"
  89.     if the number of items in field "To be Decoded" > 2 then
  90.       alert("This message is not properly formated!")
  91.       puppetTransition(3)
  92.       set the editable of member "To be Decoded" to 1
  93.       abort()
  94.     end if
  95.     if the number of chars in item 1 of field "To be Decoded" > 15 then
  96.       alert("This message is not properly formated:" & RETURN & "sender's name too long.")
  97.       puppetTransition(3)
  98.       set the editable of member "To be Decoded" to 1
  99.       abort()
  100.     end if
  101.   else
  102.     alert("This message is not properly formated:" & RETURN & "sender's name missing")
  103.     puppetTransition(3)
  104.     set the editable of member "To be Decoded" to 1
  105.     abort()
  106.   end if
  107. end
  108.  
  109. on convertToUpperCase toConvert
  110.   set convertedString to EMPTY
  111.   repeat with i = 1 to the number of chars in toConvert
  112.     if charToNum(char i of toConvert) > 90 then
  113.       set convertedChar to numToChar(getProp(gUpperCaseTable, char i of toConvert))
  114.       put convertedChar after convertedString
  115.       next repeat
  116.     end if
  117.     put char i of toConvert after convertedString
  118.   end repeat
  119.   return convertedString
  120. end
  121.  
  122. on clearAllFields
  123.   repeat with x = 1 to the number of castMembers of castLib 1
  124.     if the type of member x = #field then
  125.       put EMPTY into field x
  126.     end if
  127.     updateStage()
  128.   end repeat
  129.   if the frame = 10 then
  130.     puppetTransition(3)
  131.     updateStage()
  132.   end if
  133. end
  134.  
  135. on CopyTheResult
  136.   if field "encode:result" = EMPTY then
  137.     alert("There is no secret code to copy!!")
  138.   end if
  139.   copyToClipBoard(member "encode:result")
  140. end
  141.  
  142. on Paste
  143.   pasteClipBoardInto(member 1000 of castLib 1)
  144.   set the name of member 1000 of castLib 1 to "xxx"
  145.   if not (the type of member 1000 of castLib 1 = #field) then
  146.     alert("The ClipBpard contains invalid information!")
  147.   else
  148.     if the number of chars in the text of member 1000 of castLib 1 > 99 then
  149.       alert("The ClipBpard contains invalid information!")
  150.     else
  151.       put the text of member 1000 of castLib 1 into field "To be Decoded"
  152.     end if
  153.   end if
  154. end
  155.  
  156. on doSomeFancyStuff
  157.   if the optionDown then
  158.     return 
  159.   end if
  160.   set the memberNum of sprite 12 to the number of member "Hand Up"
  161.   DoUpAndDown(1)
  162.   set the memberNum of sprite 12 to the number of member "Operating"
  163.   puppetSound("encoding sound")
  164.   set the visible of sprite 8 to 1
  165.   repeat with i = 1 to 70
  166.     startTimer()
  167.     repeat while the timer < 7
  168.       nothing()
  169.     end repeat
  170.     updateStage()
  171.   end repeat
  172.   set the visible of sprite 8 to 0
  173.   set the memberNum of sprite 12 to the number of member "Hand Down"
  174.   DoUpAndDown(0)
  175.   puppetSound("finished encoding sound")
  176.   updateStage()
  177. end
  178.  
  179. on DoUpAndDown x
  180.   if x then
  181.     puppetSprite(12, 1)
  182.   end if
  183.   repeat with i = 1 to 5
  184.     updateStage()
  185.     startTimer()
  186.     repeat while the timer < 10
  187.       nothing()
  188.     end repeat
  189.   end repeat
  190.   if not x then
  191.     set the memberNum of sprite 12 to the number of member "standBy"
  192.     puppetSprite(12, 0)
  193.   end if
  194. end
  195.  
  196. on displayResult nameOfSender, deCodeResult
  197.   doSomeFancyStuff()
  198.   set the loc of sprite 3 to point(300, 235)
  199.   repeat with i = 1 to the number of chars in nameOfSender
  200.     puppetSound("rotating letter sound")
  201.     updateStage()
  202.     spinTheLetter(3)
  203.     if not getOne(gValidKeyList, char i of nameOfSender) then
  204.       set the memberNum of sprite 3 to the number of member "?"
  205.     else
  206.       if char i of nameOfSender = " " then
  207.         set the memberNum of sprite 3 to the number of member "blank"
  208.       else
  209.         set the memberNum of sprite 3 to the number of member char i of nameOfSender
  210.       end if
  211.     end if
  212.     set the trails of sprite 3 to 1
  213.     puppetSound("rotating letter stop sound")
  214.     updateStage()
  215.     repeat while soundBusy(1)
  216.       nothing()
  217.     end repeat
  218.     updateStage()
  219.     set the trails of sprite 3 to 0
  220.     if i = the number of chars in nameOfSender then
  221.       set the trails of sprite 3 to 1
  222.       exit repeat
  223.     end if
  224.     set the locH of sprite 3 to the locH of sprite 3 + 14
  225.     set the editable of member "To be Decoded" to 1
  226.     puppetSound("rotating letter sound")
  227.     updateStage()
  228.   end repeat
  229.   set the loc of sprite 4 to point(230, 281)
  230.   set numOfChars to the number of chars in deCodeResult
  231.   set numOffSet to 0
  232.   repeat with i = 1 to numOfChars
  233.     puppetSound("rotating letter sound")
  234.     updateStage()
  235.     spinTheLetter(4)
  236.     if (i = 21) or (i = 42) or (i = 63) then
  237.       if char i - numOffSet - 1 of deCodeResult = " " then
  238.         set the memberNum of sprite 4 to the number of member "blank"
  239.         set numOffSet to numOffSet + 1
  240.         set numOfChars to numOfChars + 1
  241.       else
  242.         if (char i - numOffSet + 1 of deCodeResult <> " ") and (char i - numOffSet of deCodeResult <> " ") then
  243.           set the memberNum of sprite 4 to the number of member "-"
  244.           set numOffSet to numOffSet + 1
  245.           set numOfChars to numOfChars + 1
  246.         end if
  247.       end if
  248.     else
  249.       if not getOne(gValidKeyList, char i - numOffSet of deCodeResult) then
  250.         set the memberNum of sprite 4 to the number of member "?"
  251.       else
  252.         if char i - numOffSet of deCodeResult = " " then
  253.           set the memberNum of sprite 4 to the number of member "blank"
  254.         else
  255.           set the memberNum of sprite 4 to the number of member char i - numOffSet of deCodeResult
  256.         end if
  257.       end if
  258.     end if
  259.     set the trails of sprite 4 to 1
  260.     puppetSound("rotating letter stop sound")
  261.     updateStage()
  262.     repeat while soundBusy(1)
  263.       nothing()
  264.     end repeat
  265.     updateStage()
  266.     set the trails of sprite 4 to 0
  267.     case i of
  268.       21:
  269.         set the loc of sprite 4 to point(230, 281) + point(0, 27)
  270.       42:
  271.         set the loc of sprite 4 to point(230, 281) + point(0, 54)
  272.       63:
  273.         set the loc of sprite 4 to point(230, 281) + point(0, 81)
  274.       otherwise:
  275.         set the locH of sprite 4 to the locH of sprite 4 + 14
  276.     end case
  277.   end repeat
  278. end
  279.  
  280. on spinTheLetter x
  281.   repeat with i = 1 to 10
  282.     set nextMem to the memberNum of sprite x + 1
  283.     if nextMem >= (the number of member "blank" + 3) then
  284.       set nextMem to the number of member "blank"
  285.     end if
  286.     set the memberNum of sprite x to nextMem
  287.     updateStage()
  288.     startTimer()
  289.     repeat while the timer < 2
  290.       nothing()
  291.     end repeat
  292.   end repeat
  293. end
  294.